<template>
	<view>
		<view class="header status_bar" :class="scrrol == true ? 'scrrolHeader' : ''">
			<view class="back iconfont icon-xiangzuo1" @tap="backPage"></view>
			<view class="text" :class="scrrol == true ? 'scrrolHeader' : ''">我的合同</view>
		</view>			
		<view class="clear_box"></view>
		
		<block v-for="(item, index) in info">
			<view class="records_list">
				<view class="text_box">
					<view class="title">
						<view class="t">{{item.title}}</view>
					</view>				
				</view>
				<view class="text_box02">
					<view class="type" v-if="item.status == 1">等待签署</view>
					<view class="type" v-if="item.status == 2 && item.is_sign_a==0">对方已签，等待我方签署</view>
					<view class="type" v-if="item.status == 2 && item.is_sign_b==1">我方已签，等待对方签署</view>
					<view class="type" v-if="item.status == 3">已完成</view>
					<view class="type" v-if="item.status == 6">已作废</view>
					<view class="menu_box">
						<view class="menu02" @click="contractDownload(item.id)">下载</view>
						<view class="menu01" v-if="item.status != 6" @click="contractView(item.id)">查看</view>
						<view class="menu01" v-if="item.status == 1 || (item.status == 2 && item.is_sign_b==0)" @click="contractSign(item.id)">签约</view>
					</view>
				</view>
			</view>
		</block>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				scrrol:false,
				info:'',
				
			}
		},
		onLoad() {
			let that = this;
			that.loadData();
		},
		methods: {
			loadData() {
				let that = this;
				that.Net._get('auth/contract', {}, res => {
					if (res.code == 200) {
						that.info = res.data.data;
					}
				});
			},
			contractView(e){
				let that = this;
				that.Net._get('auth/covenant_view',{id:e}, res => {
					if(res.code == 200){
						that.webviewUrl = res.data
						const textToCopy = res.data;
						// navigator.clipboard.writeText(textToCopy);
						if(textToCopy == '' || textToCopy == null){
							that.Msg.Fail('地址有误，复制失败', res => {
								
							});
							return "";
						}
						uni.setClipboardData({
						    data: textToCopy,
						    success: function () {
						        uni.showToast({
									title: '预览地址复制成功，请前往浏览器查看',
									icon: 'success',
						            duration: 2000
						        });
						    }
						});
					}
				});
			},
			contractSign(e){
				let that = this;
				that.Net._get('auth/covenant_sign',{id:e}, res => {
					if(res.code == 200){
						that.webviewUrl = res.data
						const textToCopy = res.data;
						// navigator.clipboard.writeText(textToCopy);
						if(textToCopy == '' || textToCopy == null){
							that.Msg.Fail('签约信息有误，签约地址获取失败', res => {
								
							});
							return "";
						}
						uni.setClipboardData({
						    data: textToCopy,
						    success: function () {
						        uni.showToast({
									title: '签署地址复制成功，请前往浏览器查看',
									icon: 'success',
						            duration: 2000
						        });
						    }
						});
					}
				});
			},
			contractDownload(e){
				let that = this;
				uni.showLoading({
					title: '地址复制中'
				});
				that.Net._get('auth/covenant_download',{id:e}, rs => {
					if(rs.code == 200){
						that.webviewUrl = rs.data
						const textToCopy = rs.data;
						// navigator.clipboard.writeText(textToCopy);
						if(textToCopy == '' || textToCopy == null){
							that.Msg.Fail('地址有误，复制失败', rs => {
								
							});
							return "";
						}
						uni.setClipboardData({
						    data: textToCopy,
						    success: function () {
						        uni.showToast({
									title: '下载地址复制成功，请前往浏览器查看',
									icon: 'success',
						            duration: 2000
						        });
						    }
						});
					}
				});
			},
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},

		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 28) {
				this.scrrol = true;
				/* #ifdef APP-PLUS */
				/* #endif */
			} else if (Object.scrollTop < 28) {
				this.scrrol = false;
				/* #ifdef APP-PLUS */
				/* #endif */
			}
		},
		onReachBottom() {
			var that = this;
			that.page++;
			that.Net._get('auth/contract', {per_page:'10',page:that.page,}, res => {
				if (res.code == 200) {
				//console.log(res)
					if (res.data.data == '') {
						uni.showToast({
							title: '已经是最后一页了',
							duration: 2000,
							icon: 'none'
						});
					} else {
						that.info = that.info.concat(res.data.data); //将数据拼接在一起
					}
				} else if (res.code == 0) {
					that.Msg.Success(res.msg, res => {});
				}
			});
		},
	}
</script>

<style>
	
	.scrrolHeader{
		background-color: #FF7701 !important;
	}
	
	.records_list{
		width: 92%;
		margin: 4% auto 0;
		background-color: #fff;
		padding: 5vw 4vw;
		border-radius: 3vw;
	}
	
	.records_list .text_box{
		width: 100%;
	}
	
	
	
	.records_list .text_box .title{
		width: 100%;
		display: flex;
		align-items: center;
	}
	
	.records_list .text_box .title .t{
		font-size: 4.5vw;
		color: #333;
		font-weight: bold;
	}
	
	.records_list .text_box .title .type{
		height: 7vw;
		padding: 0 2vw;
		border: 1px solid #E0E0E2;
		border-radius: 1vw;
		font-size: 3vw;
		color: #444344;
		margin-left: 2vw;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.records_list .text_box .time{
		font-size: 3.5vw;
		color: #999999;
		text-align: right;
		margin-top: 3vw;
	}
	
	.records_list .text_box .money{
		font-size: 4.5vw;
		color: #333;
		font-weight: bold;
		text-align: right;
	}
	
	.records_list .text_box .text{
		font-size: 3.5vw;
		color: #3E3E3E;
		margin-top: 3vw;
	}
	
	.records_list .text_box02{
		width: 100%;
		margin-top: 5vw;
		padding-top: 5vw;
		border-top: 1px solid #F0F0F0;
		display: flex;
		align-items: center;
	}
	
	.records_list .text_box02 .type{
		height: 7vw;
		padding: 0 1vw;
		border: 1px solid #E0E0E2;
		border-radius: 1vw;
		font-size: 3vw;
		color: #444344;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.records_list .text_box02 .menu_box{
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}
	
	.records_list .text_box02 .menu_box .menu01{
		width: 14vw;
		height: 9vw;
		background-color: #FF7701;
		border-radius: 9vw;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 3.5vw;
		color: #fff;
		margin-left: 3vw;
	}
	
	.records_list .text_box02 .menu_box .menu02{
		width: 14vw;
		height: 9vw;
		background-color: transparent;
		border-radius: 9vw;
		border: 1px solid #E0E0E0;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 3.5vw;
		color: #999999;
	}
	
	
	
</style>
